home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / Locus / Source / Inspector.m < prev    next >
Text File  |  1995-06-12  |  6KB  |  301 lines

  1.  
  2. /*
  3.     Copyright 1993  Jeremy Slade.  All rights reserved.
  4. */
  5.  
  6. #import "Inspector.h"
  7.  
  8. #import "Folder.h"
  9. #import "FolderViewer.h"
  10. #import "Globals.h"
  11. #import "Group.h"
  12. #import "GroupInsPane.h"
  13. #import "InspectorPane.h"
  14. #import "ItemCell.h"
  15. #import "ItemList.h"
  16. #import "SwapView.h"
  17.  
  18. #import <strings.h>
  19.  
  20.  
  21. // Inspector mode strings -- for modeMenu items
  22. char *inspectorTitles[] = { "None", "Item", "Group", "Folder", NULL };
  23.  
  24.  
  25. @implementation Inspector
  26.  
  27.  
  28. // -------------------------------------------------------------------------
  29. //   Creating, Initializing
  30. // -------------------------------------------------------------------------
  31.  
  32.  
  33. + initialize
  34. {
  35.     [self setVersion:Inspector_VERSION];
  36.     return ( self );
  37. }
  38.  
  39.  
  40.  
  41. - init
  42. {
  43.     [super init];
  44.     
  45.     [NXApp loadNibSection:"Inspector.nib" owner:self withNames:NO];
  46.     [panel moveTo:inspectorLocation.x :inspectorLocation.y];
  47.     [panel setBecomeKeyOnlyIfNeeded:YES];
  48.     
  49.     currentPane = noInspectorPane;
  50.     previousMode = INSPECT_GROUP;
  51.     if ( inspectorMode != INSPECT_NONE ) [self setInspectorMode:inspectorMode];
  52.  
  53.     return ( self );
  54. }
  55.  
  56.  
  57.  
  58. - awakeFromNib
  59. /*
  60.     Perform final initializations
  61. */
  62. {
  63.     currentPane = noInspectorPane;
  64.     previousMode = INSPECT_GROUP;
  65.     if ( inspectorMode != INSPECT_NONE ) [self setInspectorMode:inspectorMode];
  66.  
  67.     return ( self );
  68. }
  69.  
  70.  
  71.  
  72. - free
  73. {
  74.     return ( [super free] );
  75. }
  76.  
  77.  
  78.  
  79. // -------------------------------------------------------------------------
  80. //   Showing the inspector and setting the mode
  81. // -------------------------------------------------------------------------
  82.  
  83.  
  84. - showInspector:sender
  85. {
  86.     if ( inspectorMode == INSPECT_NONE ) {
  87.         [self setInspectorMode:previousMode];
  88.     }
  89.  
  90.     [panel disableFlushWindow];
  91.     
  92.     [paneView swap];
  93.     [currentPane inspect:target];
  94.     [currentPane showCurrent:self];
  95.     [panel display];
  96.     
  97.     [[panel reenableFlushWindow] flushWindow];
  98.  
  99.     if ( ![panel isVisible] ) {
  100.         [panel moveTo:inspectorLocation.x :inspectorLocation.y];
  101.         [panel orderFront:self];
  102.     }
  103.     return ( self );
  104. }
  105.  
  106.  
  107.  
  108.  
  109. - panel
  110. {
  111.     return ( panel );
  112. }
  113.  
  114.  
  115.  
  116. - setFolderMode:sender
  117. {
  118.     return ( [self setInspectorMode:INSPECT_FOLDER] );
  119. }
  120.  
  121.  
  122.  
  123. - setGroupMode:sender
  124. {
  125.     return ( [self setInspectorMode:INSPECT_GROUP] );
  126. }
  127.  
  128.  
  129.  
  130. - setItemMode:sender
  131. {
  132.     return ( [self setInspectorMode:INSPECT_ITEM] );
  133. }
  134.  
  135.  
  136.  
  137. - setInspectorMode:(int)aMode
  138. {
  139.     int oldMode;
  140.  
  141.     oldMode = inspectorMode;
  142.     
  143.     switch ( aMode ) {
  144.         case INSPECT_ITEM:
  145.         case INSPECT_GROUP:
  146.         case INSPECT_FOLDER:
  147.             inspectorMode = aMode;
  148.             if ( ![panel isVisible] ) {
  149.                 [panel moveTo:inspectorLocation.x :inspectorLocation.y];
  150.                 [panel orderFront:self];
  151.             }
  152.             break;
  153.         case INSPECT_NONE:
  154.         default:
  155.             // Save the current mode so it can be restored later
  156.             previousMode = inspectorMode;
  157.             inspectorMode = INSPECT_NONE;
  158.             [panel orderOut:self]; // Make sure the inspector gets hidden
  159.             break;
  160.     }
  161.     
  162.     // Save the inspectorMode to defaults database if it has changed
  163.     if ( inspectorMode != oldMode ) {
  164.         NXWriteDefault ( [NXApp appName], PREF_INSPECTORMODE,
  165.             inspectorTitles[inspectorMode] );
  166.     }
  167.     
  168.     [modeCover setTitle:inspectorTitles[inspectorMode]];
  169.     [paneView swap];    // Make sure we have the current pane for this mode
  170.     [self update];            // Then make sure we have a current target
  171.     return ( self );
  172. }
  173.  
  174.  
  175.  
  176. - (int)inspectorMode
  177. {
  178.     return ( inspectorMode );
  179. }
  180.  
  181.  
  182.  
  183. - (BOOL)canInspect:anObject
  184. {
  185.     if ( [currentPane canInspect:anObject] || !anObject )
  186.         return ( YES );
  187.     switch ( inspectorMode ) {
  188.         case INSPECT_FOLDER: return ( [anObject isKindOf:[Folder class]] );
  189.         case INSPECT_GROUP: return ( [anObject isKindOf:[Group class]] );
  190.         case INSPECT_ITEM: return ( [anObject isKindOf:[ItemCell class]] ||
  191.             [anObject isKindOf:[ItemList class]] );
  192.     }
  193.     return ( NO );
  194. }
  195.  
  196.  
  197.  
  198. - inspect:anObject
  199. {
  200.     if ( [self canInspect:anObject] ) {
  201.         target = anObject;
  202.         [self showInspector:self];
  203.         return ( self );
  204.     } else
  205.         return ( nil );
  206. }
  207.     
  208.  
  209.  
  210. - inspecting
  211. {
  212.     return ( target );
  213. }
  214.  
  215.  
  216.  
  217. - update
  218. {    
  219.     [NXApp sendAction:@selector(updateInspector:)
  220.         to:[NXApp calcTargetForAction:@selector(updateInspector:)]
  221.         from:self];
  222.     return ( self );
  223. }
  224.  
  225.  
  226.  
  227. // -------------------------------------------------------------------------
  228. //   Selecting the Group Name field
  229. // -------------------------------------------------------------------------
  230.  
  231.  
  232. - selectGroupName:sender
  233. /*
  234. This method is called when a new group is created.  It makes the InspectorPanel the key window and selects the Name field in the Group pane, so that the user can immediately type in the name for the new group.
  235. */
  236. {
  237.     [self setGroupMode:self];
  238.     [groupPane selectNameField:sender];
  239.     return ( self );
  240. }
  241.  
  242.  
  243.  
  244. // -------------------------------------------------------------------------
  245. //   SwapView delegate methods
  246. // -------------------------------------------------------------------------
  247.  
  248.  
  249. - swapPaneFor:sender
  250. {
  251.     if ( !target )
  252.         currentPane = noInspectorPane;
  253.     else switch ( inspectorMode ) {
  254.         case INSPECT_FOLDER:    currentPane = folderPane; break;
  255.         case INSPECT_GROUP:    currentPane = groupPane; break;
  256.         case INSPECT_ITEM:    
  257.             currentPane = [target isKindOf:[ItemList class]] 
  258.                 ? selectionPane : itemPane;
  259.             break;
  260.     }
  261.     return ( currentPane );
  262. }
  263.  
  264.  
  265.  
  266. // -------------------------------------------------------------------------
  267. //   Window Delegate methods
  268. // -------------------------------------------------------------------------
  269.  
  270.  
  271. - windowDidMove:sender
  272. {
  273.     if ( sender == panel ) {
  274.         // Save new location in defaults database
  275.         char buf[21];
  276.         NXRect rect;
  277.         [panel getFrame:&rect];
  278.         inspectorLocation = rect.origin;
  279.         sprintf ( buf, "%.0f %.0f", rect.origin.x, rect.origin.y );
  280.         NXWriteDefault ( [NXApp appName], PREF_INSPECTORLOCATION, buf );
  281.     }
  282.     
  283.     return ( self );
  284. }
  285.  
  286.  
  287.  
  288. - windowWillClose:sender
  289. {
  290.     if ( sender == panel ) {
  291.         [self setInspectorMode:INSPECT_NONE];
  292.     }
  293.     return ( self );
  294. }
  295.  
  296.  
  297.  
  298. @end
  299.  
  300.  
  301.